﻿///***************************************************************
/// 시  스  템 : Updms.Dvd
/// 단위시스템 : DVD
/// 계      층 : Presentation Layer
/// 프로그램명 : Dvd1012m
/// 파  일  명 : Dvd1012m.aspx.cs
/// 설      명 : DVD관리
///***************************************************************
/// 수정ID 일자       이름     내용
///---------------------------------------------------------------
/// CH001  2008-08-05 송시명   최초 작성
///***************************************************************
using System;
using System.Collections;
using System.Data;
using System.IO;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using SMFramework.Data;
using SMFramework.Utility;
using SMFramework.Web.UI.WebControls.Page;

using Base.AppFramework.Web.UI.CommandBar;
using Base.Dac;

using Updms.Dvd.Exe;


namespace Updms.Dvd
{
	public partial class Dvd1012m : Updms.Common.BaseClass.PageBase
	{
		#region 전역영역

		//프로그램상수
		public static readonly string PID = "Dvd1012m";
		public static readonly string gs_path_info = "/updms/Dvd/" + PID + ".aspx";

		Global global = new Global();
		CommCode.Dvd dvd = new CommCode.Dvd(LANG_SET);

		//페이징
		private int li_cur_page, li_row_count, li_st_page, li_ed_page;
		protected int li_page_size = GRID_PAGESIZE;// 한 페이지에 출력될 행의수

		//검색
		protected string kw1 = "";	//스튜디오
		protected string kw2 = "";	//제목
		protected string kw3 = "";	//주연
		protected string kw4 = "";	//평점
		protected string kw5 = "";	//내용
		protected string kw6 = "";	//외모
		protected string kw7 = "";	//복장
		protected string kw8 = "";	//캐릭터

		//메뉴 선택값
		protected string gs_sm = "";

		#endregion

		#region Page_Load, OnPageLoad

		protected void Page_Load(object sender, EventArgs e)
		{
			SetInit();
			if (!Page.IsPostBack)
			{
				//최초 화면 로딩시 처리해야 할 부분
				OnPageLoad();
				SelectProcess();
			}
			SetClientScriptNoPostBack();
		}

		//OnPageLoad
		private void OnPageLoad()
		{
			SetLiterals(global.GetLabelInfoByPgmId(PID, LANG_SET));
			SetClientScript();
			SetSearchStudio();
			SetSearchContents();
			SetSearchLook();
			SetSearchCostume();
			SetSearchCharacter();
			SetDiv();
			SetDvdNo();
			SetStudioList();
			SetContents();
			SetLook();
			SetCostume();
			SetCharacter();
			SetSearchParameter();
		}

		#endregion

		#region InitializeComponent

		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);
			this.PreRender += new System.EventHandler(this.Page_PreRender);
		}

		#endregion

		#region SetClientScript, SetClientScriptNoPostBack

		private void SetClientScript()
		{
			txt_file_size.Attributes.Add("onkeyup", "form1.txt_file_size.value=addComma(form1.txt_file_size.value);");
			
			//onKeyPress이벤트 (엔터검색)
			txt_search_title.Attributes.Add("onkeypress", "enterSearch(event)");
			txt_search_actress1.Attributes.Add("onkeypress", "enterSearch(event)");
			txt_search_rate.Attributes.Add("onkeypress", "enterSearch(event)");

			//달력콘트롤 설정
			ce_release_dt.SelectedDate = DateTime.Now.AddDays(0);
		}

		//포스트백과 무관하게 이벤트 지정
		private void SetClientScriptNoPostBack()
		{
			cbl_search_studio.Items[0].Attributes.Add("onclick", "checkBoxListCheck('cbl_search_studio');");
			cbl_search_contents.Items[0].Attributes.Add("onclick", "checkBoxListCheck('cbl_search_contents');");
			cbl_search_look.Items[0].Attributes.Add("onclick", "checkBoxListCheck('cbl_search_look');");
			cbl_search_costume.Items[0].Attributes.Add("onclick", "checkBoxListCheck('cbl_search_costume');");
			cbl_search_character.Items[0].Attributes.Add("onclick", "checkBoxListCheck('cbl_search_character');");
		}

		#endregion

		#region SetInit, SetSearchParameter, ShowKeywordLabel

		//초기값설정
		private void SetInit()
		{
			lbl_search_flag.Text = "INIT";
			if (Request.QueryString["page"] == null || int.Parse(Request.QueryString["page"]) == 1)
			{
				li_cur_page = 1;
				li_st_page = 0;
				li_ed_page = li_page_size;
			}
			else
			{
				li_cur_page = int.Parse(Request.QueryString["page"]);
				li_st_page = (int.Parse(Request.QueryString["page"]) - 1) * li_page_size;
				li_ed_page = li_st_page + li_page_size;
			}

			gs_sm = (Request.QueryString["sm"] == null || Request.QueryString["sm"].Trim().Length != 7)
					? global.GetDirDepth(PID) : Request.QueryString["sm"].ToString();
		}

		//검색파라미터
		private void SetSearchParameter()
		{
			switch (lbl_search_flag.Text.Trim().ToUpper())
			{
				case "INIT":
					if (String.IsNullOrEmpty(Request.QueryString["kw1"]))
					{
						kw1 = WebControlUtil.GetCheckBoxListValue(cbl_search_studio, 1);
					}
					else
					{
						kw1 = Server.UrlDecode(Request.QueryString["kw1"]);
						WebControlUtil.SetCheckBoxListValue(cbl_search_studio, kw1);
					}

					if (String.IsNullOrEmpty(Request.QueryString["kw2"]))	// url에 값이 없으면
					{
						kw2 = txt_search_title.Text.Trim();
					}
					else
					{
						kw2 = Server.UrlDecode(Request.QueryString["kw2"]);
						txt_search_title.Text = kw2;
					}

					if (String.IsNullOrEmpty(Request.QueryString["kw3"]))	// url에 값이 없으면
					{
						kw3 = txt_search_actress1.Text.Trim();
					}
					else
					{
						kw3 = Server.UrlDecode(Request.QueryString["kw3"]);
						txt_search_actress1.Text = kw3;
					}

					if (String.IsNullOrEmpty(Request.QueryString["kw4"]))	// url에 값이 없으면
					{
						kw4 = txt_search_rate.Text.Trim();
					}
					else
					{
						kw4 = Server.UrlDecode(Request.QueryString["kw4"]);
						txt_search_rate.Text = kw4;
					}					
	
					if (String.IsNullOrEmpty(Request.QueryString["kw5"]))
					{
						kw5 = WebControlUtil.GetCheckBoxListValue(cbl_search_contents, 1);
					}
					else
					{
						kw5 = Server.UrlDecode(Request.QueryString["kw5"]);
						WebControlUtil.SetCheckBoxListValue(cbl_search_contents, kw5);
					}

					if (String.IsNullOrEmpty(Request.QueryString["kw6"]))
					{
						kw6 = WebControlUtil.GetCheckBoxListValue(cbl_search_look, 1);
					}
					else
					{
						kw6 = Server.UrlDecode(Request.QueryString["kw6"]);
						WebControlUtil.SetCheckBoxListValue(cbl_search_look, kw6);
					}

					if (String.IsNullOrEmpty(Request.QueryString["kw7"]))
					{
						kw7 = WebControlUtil.GetCheckBoxListValue(cbl_search_costume, 1);
					}
					else
					{
						kw7 = Server.UrlDecode(Request.QueryString["kw7"]);
						WebControlUtil.SetCheckBoxListValue(cbl_search_costume, kw7);
					}

					if (String.IsNullOrEmpty(Request.QueryString["kw8"]))
					{
						kw8 = WebControlUtil.GetCheckBoxListValue(cbl_search_character, 1);
					}
					else
					{
						kw8 = Server.UrlDecode(Request.QueryString["kw8"]);
						WebControlUtil.SetCheckBoxListValue(cbl_search_character, kw8);
					}
					break;
				case "SEARCH":
					kw1 = WebControlUtil.GetCheckBoxListValue(cbl_search_studio, 1);
					kw2 = txt_search_title.Text.Trim();
					kw3 = txt_search_actress1.Text.Trim();
					kw4 = txt_search_rate.Text.Trim();
					kw5 = WebControlUtil.GetCheckBoxListValue(cbl_search_contents, 1);
					kw6 = WebControlUtil.GetCheckBoxListValue(cbl_search_look, 1);
					kw7 = WebControlUtil.GetCheckBoxListValue(cbl_search_costume, 1);
					kw8 = WebControlUtil.GetCheckBoxListValue(cbl_search_character, 1);
					break;
			}
		}

		//검색키워드
		private void ShowKeywordLabel()
		{
			string ls_kw1 = WebControlUtil.GetCheckBoxListText(cbl_search_studio, 1);
			string ls_kw5 = WebControlUtil.GetCheckBoxListText(cbl_search_contents, 1);
			string ls_kw6 = WebControlUtil.GetCheckBoxListText(cbl_search_look, 1);
			string ls_kw7 = WebControlUtil.GetCheckBoxListText(cbl_search_costume, 1);
			string ls_kw8 = WebControlUtil.GetCheckBoxListText(cbl_search_character, 1);

			lbl_search_keyword.Text = ls_kw1 + " / " + kw2 + " / " + kw3 + " / " + kw4 + " / " + ls_kw5 + " / " + ls_kw6 + " / " + ls_kw7 + " / " + ls_kw8;
		}

		#endregion

		#region 마스터 Method (SetSearchStudio, SetSearchContents, SetSearchLook, SetSearchCostume, SetSearchCharacter)

		//스튜디오(검색)
		private void SetSearchStudio()
		{
			DataSet lo_ds = new DataSet();
			Dvd1010m_NT _Dvd1010m_NT = new Dvd1010m_NT();

			lo_ds.Merge(_Dvd1010m_NT.GetRegStudioList());

			cbl_search_studio.Items.Clear();
			cbl_search_studio.DataSource = lo_ds;
			cbl_search_studio.DataMember = "UPDMS_DVD_STUDIO";
			cbl_search_studio.DataTextField = "Text";
			cbl_search_studio.DataValueField = "Value";
			cbl_search_studio.DataBind();

			cbl_search_studio.Items.Insert(0, new ListItem(GetXmlMsg("STR_019"), "ALL"));	//전체선택
		}

		//내용
		private void SetSearchContents()
		{
			dvd.SetContents(cbl_search_contents);
			cbl_search_contents.Items.Insert(0, new ListItem(GetXmlMsg("STR_019"), "ALL"));	//전체선택
		}

		//외모
		private void SetSearchLook()
		{
			dvd.SetLook(cbl_search_look);
			cbl_search_look.Items.Insert(0, new ListItem(GetXmlMsg("STR_019"), "ALL"));	//전체선택
		}

		//복장
		private void SetSearchCostume()
		{
			dvd.SetCostume(cbl_search_costume);
			cbl_search_costume.Items.Insert(0, new ListItem(GetXmlMsg("STR_019"), "ALL"));	//전체선택
		}

		//특징
		private void SetSearchCharacter()
		{
			dvd.SetCharacter(cbl_search_character);
			cbl_search_character.Items.Insert(0, new ListItem(GetXmlMsg("STR_019"), "ALL"));	//전체선택
		}

		#endregion

		#region 디테일1 Method (SetDiv, SetDvdNo, SetStudioList)

		//구분
		private void SetDiv()
		{
			dvd.SetDiv(ddl_div);
		}

		//Dvd No
		private void SetDvdNo()
		{
			DataPack lo_dp = new DataPack();

			lo_dp.AddProperty("ls_div", typeof(string), ddl_div.SelectedValue);

			using (Dvd1012m_NT _Dvd1012m_NT = new Dvd1012m_NT())
			{
				txt_dvd_no.Text = _Dvd1012m_NT.GetNewDvdNoByDiv(lo_dp);
			}
		}

		//스튜디오
		private void SetStudioList()
		{
			DataSet lo_ds = new DataSet();
			Dvd1010m_NT _Dvd1010m_NT = new Dvd1010m_NT();

			lo_ds.Merge(_Dvd1010m_NT.GetStudioList());

			ddl_studio.Items.Clear();
			ddl_studio.DataSource = lo_ds;
			ddl_studio.DataMember = "UPDMS_DVD_STUDIO";
			ddl_studio.DataTextField = "Text";
			ddl_studio.DataValueField = "Value";
			ddl_studio.DataBind();
		}

		//구분 변경시
		protected void ddl_div_SelectedIndexChanged(object sender, EventArgs e)
		{
			SetDvdNo();
		}
		
		#endregion

		#region 디테일2 Method (SetContents, SetLook, SetCostume, SetCharacter, BoundCategory)

		//내용
		private void SetContents()
		{
			dvd.SetContents(cbl_contents);
			cbl_contents.Items[0].Selected = true;
		}

		//외모
		private void SetLook()
		{
			dvd.SetLook(cbl_look);
			cbl_look.Items[0].Selected = true;
		}

		//복장
		private void SetCostume()
		{
			dvd.SetCostume(cbl_costume);
			cbl_costume.Items[0].Selected = true;
		}

		//특징
		private void SetCharacter()
		{
			dvd.SetCharacter(cbl_character);
			cbl_character.Items[0].Selected = true;
		}

		//리스트 클릭시 바인딩
		private void BoundCategory(string ls_dvd_no, string ls_div)
		{
			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();

			lo_dp.AddProperty("ls_dvd_no", typeof(string), ls_dvd_no);
			lo_dp.AddProperty("ls_div", typeof(string), ls_div);
			
			//구분별
			CheckBoxList lo_cbl = new CheckBoxList();
			switch (ls_div)
			{
				case "AC":	//내용
					lo_cbl = cbl_contents;
					break;
				case "AD":	//외모
					lo_cbl = cbl_look;
					break;
				case "AE":	//복장
					lo_cbl = cbl_costume;
					break;
				case "AF":	//특징
					lo_cbl = cbl_character;
					break;
			}

			//초기화
			WebControlUtil.SelectCheckBoxList(lo_cbl, false);

			using (Dvd1012m_NT _Dvd1012m_NT = new Dvd1012m_NT())
			{
				lo_ds.Merge(_Dvd1012m_NT.GetCategoryListByDvdNo(lo_dp));
			}

			for (int i = 0; i < lo_cbl.Items.Count; i++)
			{
				for (int j = 0; j < DataSetUtil.GetRowCount(lo_ds, "UPDMS_DVD_INFO"); j++)
				{
					string ls_value = DataSetUtil.GetFldStr(lo_ds, "UPDMS_DVD_INFO", j, "Cd");
					if (lo_cbl.Items[i].Value == ls_value)
					{
						lo_cbl.Items[i].Selected = true;
					}
				}
			}
		}		

		#endregion

		#region CRUD (SelectProcess, InsertProcess, UpdateProcess, DeleteProcess, SearchProcess)

		//조회
		private void SelectProcess()
		{
			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();
			int li_page_count;

			//검색
			lo_dp.AddProperty("ls_studio", typeof(string), kw1);
			lo_dp.AddProperty("ls_title", typeof(string), kw2);
			lo_dp.AddProperty("ls_actress", typeof(string), kw3);
			lo_dp.AddProperty("ls_rate", typeof(string), kw4);
			lo_dp.AddProperty("ls_contents", typeof(string), kw5);
			lo_dp.AddProperty("ls_look", typeof(string), kw6);
			lo_dp.AddProperty("ls_costume", typeof(string), kw7);
			lo_dp.AddProperty("ls_character", typeof(string), kw8);
			
			using (Dvd1012m_NT _Dvd1012m_NT = new Dvd1012m_NT())
			{
				li_row_count = _Dvd1012m_NT.GetSearchCount(lo_dp);	// 검색된 행수
				li_page_count = (int)((li_row_count - 1) / li_page_size) + 1;	// 총페이지수 계산

				//모두보기/페이징
				lo_dp.AddProperty("li_st_page", typeof(Int32), (cb_list_all.Checked) ? 0 : li_st_page);
				lo_dp.AddProperty("li_ed_page", typeof(Int32), (cb_list_all.Checked) ? li_row_count : li_ed_page);
				lbl_page.Visible = !cb_list_all.Checked;

				lo_ds.Merge(_Dvd1012m_NT.SelectProcess(lo_dp));

				GridView1.DataSource = lo_ds;
				GridView1.DataBind();

				string search_condition = "?sm=" + gs_sm + "&kw1=" + Server.UrlEncode(kw1) + "&kw2=" + Server.UrlEncode(kw2) + "&kw3=" + Server.UrlEncode(kw3) + "&kw4=" + Server.UrlEncode(kw4) + "&kw5=" + Server.UrlEncode(kw5) + "&kw6=" + Server.UrlEncode(kw6) + "&kw7=" + Server.UrlEncode(kw7) + "&kw8=" + Server.UrlEncode(kw8) + "&page=";

				Pager pager = new Pager(this, ref lbl_page);
				pager.PageNavigation(
					li_cur_page,
					li_page_count,
					gs_path_info + search_condition);

				//결과출력(키워드, 검색행수)
				ShowKeywordLabel();
				lbl_result_count.Text = li_row_count.ToString("#,###,##0");

				//즐겨찾기
				ibtn_favorite.Attributes.Add("onclick", "javascript:goFavoriteSearchPage('" + PID + "','" + search_condition + "');return false;");
			}
		}

		//저장
		private void InsertProcess()
		{
			using (Dvd1012m_RT _Dvd1012m_RT = new Dvd1012m_RT())
			{
				int li_return = _Dvd1012m_RT.InsertProcess(SetValue());
				string ls_msg_id = (li_return > 0) ? "MSG_INF_007" : "MSG_ERR_105";	//저장되었습니다:저장할 수 없습니다
				CallMsgBoxInAjax(ls_msg_id);

				SearchProcess();
			}
		}

		//수정
		private void UpdateProcess()
		{
			using (Dvd1012m_RT _Dvd1012m_RT = new Dvd1012m_RT())
			{
				int li_return = _Dvd1012m_RT.UpdateProcess(SetValue());
				string ls_msg_id = (li_return > 0) ? "MSG_INF_006" : "MSG_ERR_104";	//수정되었습니다:수정할 수 없습니다
				CallMsgBoxInAjax(ls_msg_id);

				SearchProcess();
			}
		}

		//카테고리저장
		private void InsertCategoryProcess()
		{
			using (Dvd1012m_RT _Dvd1012m_RT = new Dvd1012m_RT())
			{
				int li_return = _Dvd1012m_RT.InsertCategoryProcess(SetCategoryValue());
				string ls_msg_id = (li_return > 0) ? "MSG_INF_007" : "MSG_ERR_105";	//저장되었습니다:저장할 수 없습니다
			}
		}

		//삭제
		private void DeleteProcess(string ls_xml)
		{
			using (Dvd1012m_RT _Dvd1012m_RT = new Dvd1012m_RT())
			{
				int li_return = _Dvd1012m_RT.DeleteProcess(ls_xml);
				string ls_msg_id = (li_return > 0) ? "MSG_INF_004" : "MSG_ERR_103";	//삭제되었습니다:삭제할 수 없습니다
				CallMsgBoxInAjax(ls_msg_id);

				SearchProcess();
			}
		}

		//검색
		private void SearchProcess()
		{
			lbl_search_flag.Text = "SEARCH";
			SetSearchParameter();
			ClearValue();
			SelectProcess();
		}

		#endregion

		#region SetSynopsisValue, SetValue, SetCategoryValue, ClearValue

		//SetSynopsisValue
		private string SetSynopsisValue()
		{
			string ls_synopsis = "";

			ls_synopsis = WebControlUtil.GetCheckBoxListText(cbl_contents) + ",";
			ls_synopsis += WebControlUtil.GetCheckBoxListText(cbl_look) + ",";
			ls_synopsis += WebControlUtil.GetCheckBoxListText(cbl_costume) + ",";
			ls_synopsis += WebControlUtil.GetCheckBoxListText(cbl_character);

			return ls_synopsis;
		}

		//SetValue
		private DataPack SetValue()
		{
			DataPack lo_dp = new DataPack();
			
			lo_dp.AddProperty("Seq",				typeof(string),	lbl_pk.Text);
			lo_dp.AddProperty("Dvd_No",				typeof(string), txt_dvd_no.Text);
			lo_dp.AddProperty("Div",				typeof(string), ddl_div.SelectedValue);
			lo_dp.AddProperty("Studio",				typeof(string), ddl_studio.SelectedValue);
			lo_dp.AddProperty("Title",				typeof(string), txt_title.Text);
			lo_dp.AddProperty("Release_Dt",			typeof(string), ConversionUtil.DefaultValue(txt_release_dt.Text));
			lo_dp.AddProperty("Actress1",			typeof(string), ConversionUtil.DefaultValue(txt_actress1.Text, "Unknown"));
			lo_dp.AddProperty("Actress2",			typeof(string), ConversionUtil.DefaultValue(txt_actress2.Text));
			lo_dp.AddProperty("Rate",				typeof(string), ConversionUtil.DefaultValue(txt_rate.Text,"0.0"));
			lo_dp.AddProperty("Running_Time",		typeof(string), ConversionUtil.DefaultValue(ConversionUtil.ExtractNumberStr(txt_running_time.Text),"0"));
			lo_dp.AddProperty("File_Size",			typeof(string), ConversionUtil.DefaultValue(ConversionUtil.ExtractNumberStr(txt_file_size.Text),"0"));
			lo_dp.AddProperty("Synopsis",			typeof(string), SetSynopsisValue());
			lo_dp.AddProperty("Attach_File1",		typeof(string), lbl_attach_file1.Text);
			lo_dp.AddProperty("Screenshot_Width",	typeof(string), lbl_screenshot_width.Text);
			lo_dp.AddProperty("Screenshot_Height",	typeof(string), lbl_screenshot_height.Text);
			lo_dp.AddProperty("Create_User",		typeof(string), USER_ID);
			lo_dp.AddProperty("Create_Dt",			typeof(string), "");
			lo_dp.AddProperty("Update_User",		typeof(string), USER_ID);
			lo_dp.AddProperty("Update_Dt",			typeof(string), "");

			return lo_dp;
		}

		//SetCategoryValue
		private string SetCategoryValue()
		{
			StringBuilder sb = new StringBuilder();
			
			sb.Append("<UPDMS>");
			
			//루프를 돌면서 저장할 데이터를 XML로 만듬(내용)
			for (int i = 0; i < cbl_contents.Items.Count; i++)
			{
				if (cbl_contents.Items[i].Selected)
				{
					sb.Append("<UPDMS_DVD_CONTENTS>");
					sb.Append("<Dvd_No>" + txt_dvd_no.Text + "</Dvd_No>");
					sb.Append("<Cd>" + cbl_contents.Items[i].Value + "</Cd>");
					sb.Append("<Create_User>" + USER_ID + "</Create_User>");
					sb.Append("<Update_User>" + USER_ID + "</Update_User>");
					sb.Append("</UPDMS_DVD_CONTENTS>");
				}
			}

			//루프를 돌면서 저장할 데이터를 XML로 만듬(외모)
			for (int i = 0; i < cbl_look.Items.Count; i++)
			{
				if (cbl_look.Items[i].Selected)
				{
					sb.Append("<UPDMS_DVD_LOOK>");
					sb.Append("<Dvd_No>" + txt_dvd_no.Text + "</Dvd_No>");
					sb.Append("<Cd>" + cbl_look.Items[i].Value + "</Cd>");
					sb.Append("<Create_User>" + USER_ID + "</Create_User>");
					sb.Append("<Update_User>" + USER_ID + "</Update_User>");
					sb.Append("</UPDMS_DVD_LOOK>");
				}
			}

			//루프를 돌면서 저장할 데이터를 XML로 만듬(복장)
			for (int i = 0; i < cbl_costume.Items.Count; i++)
			{
				if (cbl_costume.Items[i].Selected)
				{
					sb.Append("<UPDMS_DVD_COSTUME>");
					sb.Append("<Dvd_No>" + txt_dvd_no.Text + "</Dvd_No>");
					sb.Append("<Cd>" + cbl_costume.Items[i].Value + "</Cd>");
					sb.Append("<Create_User>" + USER_ID + "</Create_User>");
					sb.Append("<Update_User>" + USER_ID + "</Update_User>");
					sb.Append("</UPDMS_DVD_COSTUME>");
				}
			}

			//루프를 돌면서 저장할 데이터를 XML로 만듬(특징)
			for (int i = 0; i < cbl_character.Items.Count; i++)
			{
				if (cbl_character.Items[i].Selected)
				{
					sb.Append("<UPDMS_DVD_CHARACTER>");
					sb.Append("<Dvd_No>" + txt_dvd_no.Text + "</Dvd_No>");
					sb.Append("<Cd>" + cbl_character.Items[i].Value + "</Cd>");
					sb.Append("<Create_User>" + USER_ID + "</Create_User>");
					sb.Append("<Update_User>" + USER_ID + "</Update_User>");
					sb.Append("</UPDMS_DVD_CHARACTER>");
				}
			}
			
			sb.Append("</UPDMS>");

			return sb.ToString();
		}

		//ClearValue
		private void ClearValue()
		{
			lbl_pk.Text = "";
			h_no.Value = "";
			SetDvdNo();
			ddl_div.SelectedIndex = 0;
			ddl_studio.SelectedIndex = 0;
			txt_title.Text = "";
			ce_release_dt.SelectedDate = DateTime.Now.AddDays(0);
			txt_actress1.Text = "";
			txt_actress2.Text = "";
			CallJavaScriptMethodInAjax("setTimeout(\"setSliderValue(0.0)\", 5);");
			txt_running_time.Text = "";
			txt_file_size.Text = "";
			txt_synopsis.Text = "";
			lbl_attach_file1.Text = "";
			ibtn_delete_attach_file1.Visible = false;
			lbl_screenshot_width.Text = "";
			lbl_screenshot_height.Text = "";
			WebControlUtil.SelectCheckBoxList(cbl_contents, false);
			WebControlUtil.SelectCheckBoxList(cbl_look, false);
			WebControlUtil.SelectCheckBoxList(cbl_costume, false);
			WebControlUtil.SelectCheckBoxList(cbl_character, false);
		}

		#endregion

		#region Page_PreRender, ChangePageMode

		// Page_PreRender
		private void Page_PreRender(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				using (AccessCheck access = new AccessCheck())
				{
					//접근권한 체크
					if (!access.CheckPgmAccessGrant(PID, USER_ID, ACCESS_LOG_INFO))
					{
						Response.Redirect(URL_NO_AUTHORITY_REDIRECT_BASE);	//사용자의 권한은 요청하신 페이지를 볼 수 없습니다
					}
					//사용권한별 버튼처리
					PagePreRender.SetVisibleCtrl(this, access.CheckPgmUsingGrant(USER_DIV, PID), access.GetVisibleCtrl(PID));
				}
			}
			ChangePageMode();
		}

		//ChangePageMode
		private void ChangePageMode()
		{
			SetGridViewHeader(global.GetColumnListByPgmId(PID, LANG_SET));
		}

		#endregion

		#region File (UploadFile, DeleteFile)

		private void UploadFile()
		{
			string ls_file_name = PID + "_";
			string upload_path = FILE_PATH_UPLOAD_SCREENSHOT + "\\";

			HttpFileCollection hfc = Request.Files;
			for (int i = 0; i < hfc.Count; i++)
			{
				HttpPostedFile hpf = hfc[i];
				if (hpf.ContentLength > 0)
				{
					ls_file_name = ls_file_name + Path.GetFileName(hpf.FileName);	//업로드시 선택한 파일명
					string ls_file_size = (hpf.ContentLength / 1000).ToString(); //파일크기
					string ls_file_ext = Path.GetExtension(hpf.FileName).Remove(0, 1).ToUpper(); //확장자
					string ls_tmp_file_name = ls_file_name; //임시파일명
					string ls_save_path = upload_path + ls_tmp_file_name; //저장경로

					string ls_file_w_size = "0"; //넓이
					string ls_file_h_size = "0"; //높이

					//이미지파일의 넓이와 높이를 구한다.
					if (ValidationUtil.IsFileExtImg(ls_file_ext))
					{
						System.Drawing.Image img = System.Drawing.Image.FromStream(hpf.InputStream);
						ls_file_w_size = img.Width.ToString();
						ls_file_h_size = img.Height.ToString();
					}

					//중복된 이름의 파일이 있으면 (1)을 붙인다.
					int j = 0;
					while (File.Exists(ls_save_path))
					{
						j++;
						ls_tmp_file_name = Path.GetFileNameWithoutExtension(ls_file_name) + "(" + j.ToString() + ")" + Path.GetExtension(ls_file_name);
						ls_save_path = upload_path + ls_tmp_file_name;
					}

					//첨부파일을 DB에 저장하기 위해 라벨에 찍어둔다
					lbl_attach_file1.Text = ls_tmp_file_name;
					lbl_screenshot_width.Text = ls_file_w_size; // 넓이
					lbl_screenshot_height.Text = ls_file_h_size; // 높이

					//확장자 검사
					if (ValidationUtil.IsFileExtAll(ls_file_ext))
					{
						//파일저장
						hpf.SaveAs(ls_save_path);
					}
					else
					{
						CallMsgBoxInAjax("MSG_ERR_115");	// 업로드할 수 없는 확장자입니다
					}
				}
			}
		}

		//DeleteFile
		private void DeleteFile(string ls_file_name, string ls_pk, bool lb_db_del, bool lb_list_yn, bool lb_alert)
		{
			string ls_attach_file = FILE_PATH_UPLOAD_SCREENSHOT + ls_file_name;

			//실제 첨부파일삭제
			if (FileUtil.IsFileExist(ls_attach_file))
			{
				File.Delete(ls_attach_file);
			}
			else
			{
				if (lb_alert)
				{
					CallMsgBoxInAjax("MSG_ERR_123");	// 삭제할 파일이 없습니다
				}
			}

			//DB에서 파일정보 삭제
			if (lb_db_del)
			{
				Dvd1012m_RT _Dvd1012m_RT = new Dvd1012m_RT();
				int li_return = _Dvd1012m_RT.DeleteAttachFile(ls_pk);
				if (li_return > 0)
				{
					ibtn_delete_attach_file1.Visible = false;
					CallMsgBoxInAjax("MSG_INF_012");	//파일이 삭제되었습니다
				}
				else
				{
					CallMsgBoxInAjax("MSG_ERR_125");	//파일을 삭제할 수 없습니다
				}
			}			

			//삭제후 다시 조회
			if (lb_list_yn)
			{
				SearchProcess();
			}
		}

		#endregion

		#region GridView이벤트

		//RowDataBound
		protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
		{
			GridView gv = (GridView)sender;
			string dirDepth = global.GetDirDepth(PID);

			if (e.Row.RowType == DataControlRowType.DataRow)
			{
				//마우스올렸을 때
				e.Row.Attributes.Add("onmouseover", "overBackground('GridView1', " + (e.Row.RowIndex + 1) + ")");
				e.Row.Attributes.Add("onmouseout", "outBackground('GridView1', 1)");

				//번호
				e.Row.Cells[1].Text = ((li_row_count - ((li_cur_page - 1) * li_page_size)) - e.Row.RowIndex).ToString();
				
				//10.Actress1_Link
				string actress = gv.DataKeys[e.Row.RowIndex].Values["Actress1"].ToString();
				string actressLink = "<span title=\"" + actress + "로 검색\" class=\"hand\" onclick=\"moveThisPage('../Dvd/Dvd1012m.aspx?sm=" + dirDepth + "&kw1=&kw2=&kw3=" + actress + "&kw4=0.0&kw5=&kw6=&kw7=&kw8=&page=1&');\">" + actress + "</span>";
				e.Row.Cells[10].Text = actressLink;

				//13.Rate_Link
				string rate = gv.DataKeys[e.Row.RowIndex].Values["Rate"].ToString();
				string rateLink = "<span title=\"" + rate + "로 검색\" class=\"hand\" onclick=\"moveThisPage('../Dvd/Dvd1012m.aspx?sm=" + dirDepth + "&kw1=&kw2=&kw3=&kw4=" + rate + "&kw5=&kw6=&kw7=&kw8=&page=1&');\">" + rate + "</span>";
				e.Row.Cells[13].Text = rateLink;
			}
		}

		//RowCommand
		protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
		{
			GridView gv = (GridView)sender;
			GridViewRow row = (GridViewRow)(((Control)e.CommandSource).NamingContainer);

			LinkButton lbtn_rc = (LinkButton)GridView1.Rows[row.RowIndex].FindControl("lbtn_rc");

			//row.Cells[0].Text.ToString();//0.체크박스
			h_no.Value					= row.Cells[1].Text.ToString();										//1.번호
			lbl_pk.Text					= gv.DataKeys[row.RowIndex].Values["Seq"].ToString();				//2.Seq
			ddl_div.SelectedValue		= row.Cells[3].Text.Trim();											//3.Div
			txt_dvd_no.Text				= row.Cells[4].Text.Trim();											//4.Dvd_No
			ddl_studio.SelectedValue	= gv.DataKeys[row.RowIndex].Values["Studio"].ToString();			//5.Studio
																											//6.Studio_Nm
			txt_title.Text				= lbtn_rc.Text;														//7.Title (template)
			txt_release_dt.Text			= gv.DataKeys[row.RowIndex].Values["Release_Dt"].ToString();		//8.Release_Dt
			txt_actress1.Text			= gv.DataKeys[row.RowIndex].Values["Actress1"].ToString();			//9.Actress1
																											//10.Actress1_Link
			txt_actress2.Text			= gv.DataKeys[row.RowIndex].Values["Actress2"].ToString();			//11.Actress2
																											//12.Rate
																											//13.Rate_Link
			txt_running_time.Text		= row.Cells[14].Text.Trim();										//14.Running_Time
			txt_file_size.Text			= row.Cells[15].Text.Trim();										//15.File_Size
			txt_synopsis.Text			= gv.DataKeys[row.RowIndex].Values["Synopsis"].ToString();			//16.Synopsis
																											//17.Synopsis_Summary
			string ls_file_name			= gv.DataKeys[row.RowIndex].Values["Attach_File1"].ToString();		//18.Attach_File1
																											//19.Attach_File1_Link
																											//20.Screenshot_Width
																											//21.Screenshot_Height
			//스샷처리
			if (!String.IsNullOrEmpty(ls_file_name))
			{
				lbl_attach_file1.Text = ls_file_name;
				lbl_screenshot_width.Text = gv.DataKeys[row.RowIndex].Values["Screenshot_Width"].ToString();
				lbl_screenshot_height.Text = gv.DataKeys[row.RowIndex].Values["Screenshot_Height"].ToString();
				ibtn_delete_attach_file1.Visible = true;
			}
			else
			{
				lbl_attach_file1.Text = "";
				lbl_screenshot_width.Text = "";
				lbl_screenshot_height.Text = "";
				ibtn_delete_attach_file1.Visible = false;
			}

			BoundCategory(txt_dvd_no.Text, "AC");
			BoundCategory(txt_dvd_no.Text, "AD");
			BoundCategory(txt_dvd_no.Text, "AE");
			BoundCategory(txt_dvd_no.Text, "AF");
			
			//자바스크립트 호출
			CallJavaScriptMethodInAjax("setTimeout(\"setSliderValue(" + gv.DataKeys[row.RowIndex].Values["Rate"].ToString() + ")\", 5);toggleStr($('span_hide_show'), 'detailHide', 'detailShow');toggleObj('div_detail_2');");
		}

		#endregion

		#region 버튼이벤트

		//검색
		protected void ibtn_search_Click(object sender, EventArgs e)
		{
			SearchProcess();
		}

		//저장
		protected void ibtn_save_Click(object sender, EventArgs e)
		{
			//스샷저장
			UploadFile();

			//카테고리 저장
			InsertCategoryProcess();
			
			if (global.CheckSaveMode("UPDMS_DVD_INFO", "Seq", lbl_pk.Text.Trim()))
			{
				UpdateProcess();
			}
			else
			{
				InsertProcess();
			}
		}

		//삭제
		protected void ibtn_delete_Click(object sender, EventArgs e)
		{
			StringBuilder sb = new StringBuilder();

			sb.Append("<UPDMS>");

			for (int i = 0; i < GridView1.Rows.Count; i++)
			{
				GridViewRow row = GridView1.Rows[i];
				HtmlInputCheckBox cb = (HtmlInputCheckBox)row.FindControl("cb_check");

				if (cb.Checked)
				{
					string ls_seq = GridView1.DataKeys[i].Values["Seq"].ToString();
					string ls_dvd_no = GridView1.DataKeys[i].Values["Dvd_No"].ToString();
					string ls_file_name = GridView1.DataKeys[i].Values["Attach_File1"].ToString();	//파일이름

					//첨부파일을 먼저 삭제한다.
					DeleteFile(ls_file_name, ls_seq, false, false, false);

					sb.Append("<UPDMS_DVD_INFO>");
					sb.Append("<Seq>" + ls_seq + "</Seq>");
					sb.Append("<Dvd_No>" + ls_dvd_no + "</Dvd_No>");
					sb.Append("</UPDMS_DVD_INFO>");
				}
			}
			sb.Append("</UPDMS>");

			DeleteProcess(sb.ToString());
		}

		//엑셀
		protected void ibtn_excel_Click(object sender, EventArgs e)
		{
			SetSearchParameter();

			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();

			lo_dp.AddProperty("ls_studio", typeof(string), kw1);
			lo_dp.AddProperty("ls_title", typeof(string), kw2);
			lo_dp.AddProperty("ls_actress", typeof(string), kw3);
			lo_dp.AddProperty("ls_rate", typeof(string), kw4);
			lo_dp.AddProperty("ls_contents", typeof(string), kw5);
			lo_dp.AddProperty("ls_look", typeof(string), kw6);
			lo_dp.AddProperty("ls_costume", typeof(string), kw7);
			lo_dp.AddProperty("ls_character", typeof(string), kw8);

			using (Dvd1012m_NT _Dvd1012m_NT = new Dvd1012m_NT())
			{
				li_row_count = _Dvd1012m_NT.GetSearchCount(lo_dp);

				lo_dp.AddProperty("li_st_page", typeof(Int32), 0);
				lo_dp.AddProperty("li_ed_page", typeof(Int32), li_row_count);

				lo_ds.Merge(_Dvd1012m_NT.SelectProcess(lo_dp));
			}
			string fileName = PID + "(" + global.GetMenuTitle(PID, LANG_SET) + ")";
			ExcelUtil.CreateExcelFileX(this.Page, fileName, lo_ds, SetExcelHeaderX(global.GetColumnListByPgmId(PID, LANG_SET)));
		}

		//스샷삭제
		protected void ibtn_delete_attach_file1_Click(object sender, EventArgs e)
		{
			DeleteFile(lbl_attach_file1.Text, lbl_pk.Text, true, true, true);
		}

		//모두보기
		protected void cb_list_all_CheckedChanged(object sender, EventArgs e)
		{
			SearchProcess();
		}

		#endregion
		
	}
}
